package mp_Blatt2;
import java.awt.Dimension;
import java.io.IOException;

import javax.swing.JComponent;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

/**
 * Erstellt ein Hilfefenster
 * diese Klasse habe ich nicht komplett selbst geschrieben,
 * die Methoden createEditorPane und createHelp
 * sind abgewandelt von
 * http://download.oracle.com/javase/tutorial/uiswing/components/editorpane.html
 * abgeschaut
 * @author Katja Dittrich
 *
 */

public class HelpFrame extends JPanel {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 7929370838154134163L;

	public HelpFrame(){
		JFrame frame = new JFrame("Hilfe");
        frame.add(createHelp());
        frame.setPreferredSize(new Dimension(340, 650));
        frame.pack();
        frame.setVisible(true);
	}
	/**
	 * Erstellt ScrollPane, darin das EditorPane
	 * @return
	 */
	private JComponent createHelp(){
		JEditorPane editorPane = createEditorPane();
        JScrollPane editorScrollPane = new JScrollPane(editorPane);
        editorScrollPane.setVerticalScrollBarPolicy(
                        JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        editorScrollPane.setPreferredSize(new Dimension(250, 145));
        editorScrollPane.setMinimumSize(new Dimension(10, 10));
		return editorScrollPane;
		
	}
	
	/**
	 * HTML datei in den Editorpane laden
	 * @return
	 */
    private JEditorPane createEditorPane() {
        JEditorPane editorPane = new JEditorPane();
        editorPane.setEditable(false);
        java.net.URL helpURL = HelpFrame.class.getResource(
                                        "Help.html");
        if (helpURL != null) {
            try {
                editorPane.setPage(helpURL);
            } catch (IOException e) {
                System.err.println("Attempted to read a bad URL: " + helpURL);
            }
        } else {
            System.err.println("Couldn't find file: TextSampleDemoHelp.html");
        }

        return editorPane;
    }
}
